#include "mt3d_cuda.h"

void mt3d::save_observation(std::string filename)
{
    std::clog << "Writing Observation file ... ";
    std::ofstream outfile;
    gctl::open_outfile(outfile, filename, ".obs.txt");

    outfile << "# x y z Zxy(real) Zxy(imag) Zyx(real) Zyx(imag) Rho_xy Phase_xy Rho_yx Phase_yx\n";
    for (size_t i = 0; i < obs_num_; i++)
    {
        outfile << obs_site_[i].vert->x << " " << obs_site_[i].vert->y << " " << obs_site_[i].vert->z << " ";
        outfile << obs_site_[i].Zxy.x << " " << obs_site_[i].Zxy.y << " ";
        outfile << obs_site_[i].Zyx.x << " " << obs_site_[i].Zyx.y << " ";
        outfile << std::norm(cuda2lcg_complex(obs_site_[i].Zxy))/(omega_*_mu0) << " " << std::arg(cuda2lcg_complex(obs_site_[i].Zxy))*180.0/pi << " ";
        outfile << std::norm(cuda2lcg_complex(obs_site_[i].Zyx))/(omega_*_mu0) << " " << std::arg(cuda2lcg_complex(obs_site_[i].Zyx))*180.0/pi << "\n";
    }
    outfile.close();
    std::clog << "done\n";
    return;
}
